//package com.lrd.snapshotorder.job;
//
//import com.lrd.snapshotorder.entity.OrderTask;
//import com.lrd.snapshotorder.service.SnapshotOrderService;
//import lombok.extern.slf4j.Slf4j;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.DisposableBean;
//import org.springframework.beans.factory.InitializingBean;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import java.util.concurrent.LinkedBlockingDeque;
//import java.util.concurrent.ThreadPoolExecutor;
//import java.util.concurrent.TimeUnit;
//
//@Component
//@Slf4j
//public class OrderJobTriggerHelper implements InitializingBean, DisposableBean {
//    private static final Logger LOGGER = LoggerFactory.getLogger(OrderJobTriggerHelper.class);
//
//    @Autowired
//    private SnapshotOrderService snapshotOrderService;
//
//    public static OrderJobTriggerHelper INSTANCE;
//
//    private ThreadPoolExecutor fastTriggerPool;
//
//    public void trigger(OrderTask orderTask) {
//        for (int i = 0; i < orderTask.getBatchSize(); i++) {
//            INSTANCE.addTask(orderTask);
//        }
//    }
//
//    public void addTask(final OrderTask orderTask) {
//        // trigger
//        fastTriggerPool.execute(() -> {
//            try {
//                //snapshotOrderService.triggerCreateSnapshotOrder(orderTask);
//            } catch (Exception e) {
//                LOGGER.error(e.getMessage(), e);
//            }
//        });
//    }
//
//    @Override
//    public void destroy() throws Exception {
//        if (fastTriggerPool != null && !fastTriggerPool.isShutdown()) {
//            fastTriggerPool.shutdownNow();
//        }
//    }
//
//    @Override
//    public void afterPropertiesSet() throws Exception {
//        INSTANCE = new OrderJobTriggerHelper();
//        fastTriggerPool = new ThreadPoolExecutor(
//                10,
//                200,
//                60L,
//                TimeUnit.SECONDS,
//                new LinkedBlockingDeque<>(1000),
//                runnable -> new Thread(runnable, "JobTriggerHelper-fastTriggerPool" + runnable.hashCode()));
//    }
//}
